/*********************************************************************************************
    *   Filename        : app_broadcast.h

    *   Description     :

    *   Author          : Weixin Liang

    *   Email           : liangweixin@zh-jieli.com

    *   Last modifiled  : 2022-12-15 14:24

    *   Copyright:(c)JIELI  2011-2022  @ , All Rights Reserved.
*********************************************************************************************/
#ifndef _APP_LE_BROADCASE_H
#define _APP_LE_BROADCASE_H

/*  Include header */
#include "typedef.h"

#ifdef __cplusplus
extern "C" {
#endif

/**************************************************************************************************
  Data Types
**************************************************************************************************/
enum {
    BROADCAST_APP_MODE_ENTER,
    BROADCAST_APP_MODE_EXIT,
    BROADCAST_A2DP_START,
    BROADCAST_A2DP_STOP,
    BROADCAST_PHONE_START,
    BROADCAST_PHONE_STOP,
    BROADCAST_EDR_DISCONN,
    BROADCAST_MUSIC_START,
    BROADCAST_MUSIC_STOP,
};

enum {
    BROADCAST_SYNC_VOL,
};

enum {
    APP_BROADCAST_STATUS_STOP,
    APP_BROADCAST_STATUS_START,
    APP_BROADCAST_STATUS_SUSPEND,
};

struct __pair_polling_info {
    u16 pair_polling_timer;
    u8 cur_pair_mode;
    u8 connect_succ_flag;
    u8 pair_succ_flag;
};
/**************************************************************************************************
  Function Declarations
**************************************************************************************************/

/* --------------------------------------------------------------------------*/
/**
 * @brief 获取接收方连接状态
 *
 * @return 接收方连接状态
 */
/* ----------------------------------------------------------------------------*/
u8 get_receiver_connected_status(void);

/* --------------------------------------------------------------------------*/
/**
 * @brief 开启广播
 *
 * @return >=0:success
 */
/* ----------------------------------------------------------------------------*/
int app_broadcast_open();

/* --------------------------------------------------------------------------*/
/**
 * @brief 关闭广播
 *
 * @param status:挂起还是停止
 *
 * @return >=0:success
 */
/* ----------------------------------------------------------------------------*/
int app_broadcast_close(u8 status);

/* --------------------------------------------------------------------------*/
/**
 * @brief 广播开关切换
 *
 * @return -1:切换失败，1:关闭成功，2：开启成功
 */
/* ----------------------------------------------------------------------------*/
int app_broadcast_switch(void);


/* --------------------------------------------------------------------------*/
/**
 * @brief 用于外部重新打开发送端的数据流
 */
/* ----------------------------------------------------------------------------*/
void app_broadcast_reset_transmitter(void);

/* --------------------------------------------------------------------------*/
/**
 * @brief 更新系统当前处于的场景
 *
 * @param scene:当前系统状态
 *
 * @return 0:success
 */
/* ----------------------------------------------------------------------------*/
int update_app_broadcast_deal_scene(int scene);

/* --------------------------------------------------------------------------*/
/**
 * @brief 广播开启情况下，不同场景的处理流程
 *
 * @param scene:当前系统状态
 *
 * @return ret < 0:无需处理，ret == 0:处理事件但不拦截后续流程，ret > 0:处理事件并拦截后续流程
 */
/* ----------------------------------------------------------------------------*/
int app_broadcast_deal(int scene);

/* --------------------------------------------------------------------------*/
/**
 * @brief 获取当前是否在退出模式的状态
 *
 * @return 1；是，0：否
 */
/* ----------------------------------------------------------------------------*/
u8 get_broadcast_app_mode_exit_flag(void);

/* --------------------------------------------------------------------------*/
/**
 * @brief 更新广播同步状态的数据
 *
 * @param type:更新项
 * @param value:更新值
 *
 * @return 0:success
 */
/* ----------------------------------------------------------------------------*/
int update_broadcast_sync_data(u8 type, int value);

/* --------------------------------------------------------------------------*/
/**
 * @brief 广播资源初始化
 */
/* ----------------------------------------------------------------------------*/
void app_broadcast_init(void);

/* --------------------------------------------------------------------------*/
/**
 * @brief 广播资源卸载
 */
/* ----------------------------------------------------------------------------*/
void app_broadcast_uninit(void);

/* --------------------------------------------------------------------------*/
/**
 * @brief 广播进入配对模式
 *
 * @param role：广播角色接收端还是发送端
 * @param mode：0-广播配对，1-连接配对
 */
/* ----------------------------------------------------------------------------*/
void app_broadcast_enter_pair(u8 role, u8 mode);

/* --------------------------------------------------------------------------*/
/**
 * @brief 退出广播配对模式
 *
 * @param role：广播角色接收端还是发送端
 */
/* ----------------------------------------------------------------------------*/
void app_broadcast_exit_pair(u8 role);

/* --------------------------------------------------------------------------*/
/**
 * @brief 非蓝牙后台情况下，在其他音源模式开启BIG，前提要先开蓝牙协议栈
 */
/* ----------------------------------------------------------------------------*/
void app_broadcast_open_in_other_mode();

/* --------------------------------------------------------------------------*/
/**
 * @brief 非蓝牙后台情况下，在其他音源模式关闭BIG
 */
/* ----------------------------------------------------------------------------*/
void app_broadcast_close_in_other_mode();

/* --------------------------------------------------------------------------*/
/**
 * @brief 轮询配对功能开关
 */
/* ----------------------------------------------------------------------------*/
void app_broadcast_pair_polling_sw();
/* --------------------------------------------------------------------------*/
/**
 * @brief 轮询配对连接标志位
 */
/* ----------------------------------------------------------------------------*/
void app_broadcast_pair_flag_set(u8 flag);
void app_broadcast_conn_flag_set(u8 flag);
#ifdef __cplusplus
};
#endif

#endif

